# @Time : 2020/8/28 11:57
# @Author : Fioman 
# @Phone : 13149920693
import cv2 as cv
import numpy as np
import imutils
"""
边缘一般被定义为像素强度的不连续性,或者更简单的定义为像素值的急剧差异和变化.
图像中边缘的分类:
"""

image = cv.imread("pic/14.png",cv.IMREAD_GRAYSCALE)
blurred = cv.GaussianBlur(image,(5,5),0)

cv.imshow("Original",image)
cv.imshow("Blurred",blurred)
cv.waitKey(0)

wide = cv.Canny(blurred,10,200)
mid = cv.Canny(blurred,30,150)
tight = cv.Canny(blurred,240,250)

cv.imshow("WideEdge",wide)
cv.imshow("MidEdge",mid)
cv.imshow("TightEdge",tight)

cv.waitKey(0)

"""
自动调整Canny边缘检测参数
滞后阈值的下阈值和上阈值
"""

def auto_canny(image,sigma=0.33):
    v = np.median(image)
    lower = int(max(0,(1.0-sigma)*v))
    upper = int(min(255,(1.0+sigma)*v))
    edged = cv.Canny(image,lower,upper)
    return edged


image = cv.imread(r"D:\chongda_raw\3oz\55--2020-08-10_18-31-30--w_1992--h_1745.bmp",cv.IMREAD_GRAYSCALE)
edged = imutils.auto_canny(image)
edgedShow = cv.resize(edged,(edged.shape[1]//4,edged.shape[0]//4),interpolation=cv.INTER_AREA)
cv.imshow("Edged",edgedShow)
cv.waitKey(0)

